<template>
	<div>
		<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item',item.id==0?'mui-active':'']" href="#item1mobile" v-for="item in cates" :key="item.id" @tap="getImages(item.id)">
							{{item.title}}
						</a>
					</div>
				</div>
			</div>
			<!-- 图片列表区 -->
			<ul class="img_ul">
				<router-link :to="'/home/photoInfo/'+item.id" class="img_li" v-for="item in list" :key = "item.id">
					<img v-lazy="item.url">
					<div class="info">
						<h3 class="info-title">{{item.title}}</h3>
					</div>
				</router-link>
			</ul>
	
	</div>
</template>

<script>
	//1，导入js文件
	import mui from '../../lib/mui/js/mui.min.js'
	/*2.初始化滑动空间*/
  
	export default({
		data(){
			return {
				cates:[],
				list:[]
			}
		},
		created(){
			this.getCatefory()
			this.getImages(0)
		},
		 mounted(){
				 mui('.mui-scroll-wrapper').scroll({
		         deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
		},
		methods:{
			getCatefory(){
				this.$http.get('http://localhost:3002/api').then(result=>{
					if(result.body.status===0){
						//手动拼接最完整分类
						result.body.message.unshift({title:"全部",id:0})
						this.cates = result.body.message
					}
				})
			},
			getImages(id){
				this.$http.get('http://localhost:3002/images').then(result=>{
					if(result.body.status==0){
						var msg
						switch (id){
							case 0:this.list = result.body.message0;
								break;
							case 1:this.list = result.body.message1;
								break;
							case 2:this.list = result.body.message2;
								break;
							case 3:this.list = result.body.message3;
								break;
								}
								
						}
					})
				}
			}
		})
</script>

<style scoped>
	*{
		touch-action: pan-y;
		}
		.img_ul{
			padding: 0;
			margin-bottom:50px;
		}
		.img_ul .img_li{
			list-style: none;
			width: 94%;
			height: 280px;
			border-radius: 2px;
			margin: 4px auto;
			box-shadow: 0 0 10px #C8C8CD;
			position: relative;
		}
		.img_ul .img_li img{
			width: 100%;
			height: 280px;
		}
	.img_ul .img_li img[lazy=loading] {
		width: 40px;
		height: 300px;
		margin: auto;
}
.info{
	width: 100%;
	color: white;
	background: rgba(0,0,0,0.4);
	position: absolute;
	bottom: 0;
}
.info .info-title{
	font-size: 14px;
}
</style>
